package com.decent.ejfadmin.report.controller;

import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.report.entity.OperatorReportDTO;
import com.decent.ejfadmin.report.request.ReportQueryParam;
import com.decent.ejfadmin.report.service.CollectCardReportService;
import com.decent.ejfadmin.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author weicx
 * @date 2018/08/01
 */
@RestController
@Slf4j
@RequestMapping("CollectCardReportController")
public class CollectCardReportController {
    @Autowired
    private CollectCardReportService collectCardReportService;
    @Autowired
    private UserService userService;


    /**
     * 收卡地区统计
     *
     * @param reportQueryParam 查询bean
     * @param page             分页组件
     * @return list
     */
    @RequestMapping("/queryAreaReport")
    public Page queryAreaReport(ReportQueryParam reportQueryParam, Page page) {

        try {
            return collectCardReportService.queryAreaReport(reportQueryParam, page);
        } catch (Exception e) {
            log.warn("收卡地区统计异常:[{}]", e);
            page.setResultList(new ArrayList<>());
            page.setTotal(0);
            return page;
        }

    }

    /**
     * 收卡运营商统计
     *
     * @param pageUnit
     * @param operatorReport
     * @return
     */
    @RequestMapping("/queryOperatorReport")
    public Page queryOperatorReport(Page pageUnit, OperatorReportDTO operatorReport) {
        try {
            return collectCardReportService.queryOperatorReport(pageUnit, operatorReport);
        } catch (Exception e) {
            log.warn("收卡运营商统计异常:[{}]", e);
            pageUnit.setResultList(new ArrayList<>());
            pageUnit.setTotal(0);
            return pageUnit;
        }
    }

    /**
     * 收卡销卡统计
     *
     * @param reportQueryParam 查询bean
     * @param page             分页组件
     * @return list
     */
    @RequestMapping("/actualSupplyCardReportPage")
    public Page actualSupplyCardReportPage(ReportQueryParam reportQueryParam, Page page) {

        try {
            return collectCardReportService.actualSupplyCardReportPage(reportQueryParam, page);
        } catch (Exception e) {
            log.warn("收卡销卡统计异常:[{}]", e);
            page.setResultList(new ArrayList<>());
            page.setTotal(0);
            return page;
        }

    }

}
